﻿using PMIS.Shared.DTO;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Documents;

namespace PMIS.TemplatePrint.User
{
    class UserDocumentRenderer : IDocumentRenderer
    {
        public void Render(FlowDocument doc, object data)
        {
            if (data is ObservableCollection<UserDto> items)
            {
                TableRowGroup? groupDetails = doc.FindName("rowsDetails") as TableRowGroup;

                Style? styleCell = doc.Resources["TableCellStyle"] as Style;
                foreach (var item in items)
                {
                    TableRow row = new TableRow();

                    TableCell cell = new TableCell(new Paragraph(new Run(item.UserName)));
                    cell.Style = styleCell;
                    cell.TextAlignment = TextAlignment.Center;
                    row.Cells.Add(cell);

                    cell = new TableCell(new Paragraph(new Run(item.RealName)));
                    cell.Style = styleCell;
                    cell.TextAlignment = TextAlignment.Center;
                    row.Cells.Add(cell);

                    cell = new TableCell(new Paragraph(new Run(item.Birthday)));
                    cell.Style = styleCell;
                    cell.TextAlignment = TextAlignment.Center;
                    row.Cells.Add(cell);

                    groupDetails?.Rows.Add(row);
                }
            }
        }
    }
}
